<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Holiday_model extends CI_Model
{	
	public function __construct()
	{
		parent::__construct();
	}
	
	function get_all_holidays()
	{
		return $this->db->get('holidays')->result();		
	}
	
	function create_holiday($insert)
	{		
		$time = explode('-',$insert['date']);
		$year_id = trim(str_replace('20','',$time[0]));
		$where = array(	'month_id'	=> $time[1]);	
		$day = 'day_'.$time[2];
		$holiday = array(
		'year_id' 	=> $year_id,
		'month_id' 	=> $time[1],
		'date_id'	=> $time[2],
		'reason'	=> $insert['reason'],
		);		
		if($this->db->insert('holidays',$holiday)){
		$this->db->where("year_id = {$year_id} AND month_id = {$time[1]} ");	
		$this->db->update('daily_attendance_sheet',array($day => 'holiday' ));		
		}
	}
	
	function delete($delete_id)
	{
		$get = $this->db->get_where('holidays',array('id' => $delete_id))->row_array();
		//$time = $get[''];
		$year_id = $get['year_id']; //trim(str_replace('20','',$time[0]));		
		$where = array(	'month_id'	=> $get['month_id']);
		$day = 'day_'.$get['date_id'];
		if($this->db->delete('holidays', array('id' => $delete_id))){
		$this->db->where("year_id = {$year_id} AND month_id = {$get['month_id']} ");	
		$this->db->update('daily_attendance_sheet',array($day => "" ));			
		}
		
	}
	
}
